package progress.exa37.loader;

import java.lang.reflect.Method;
import java.net.MalformedURLException;

/**
 * 使用自定义的类加载器对class文件加载并创建实例使用之
 */
public class LoaderStudy {

    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, MalformedURLException {

//        Class<?> aClass1 = ClassLoader.getSystemClassLoader().loadClass("file:///E:/Personal/MyRepository/study/Java基础学习/src/main/java/Progress/exa37/complier/Test.class");
//        aClass1.newInstance();
        MyClassLoader loader = new MyClassLoader();
        // 这个loadClass 的机制是重点
        Class<?> aClass = loader.loadClass("file:///E:/Personal/MyRepository/study/Java基础学习/src/main/java/Progress/exa37/complier/Test.class");
        try {
            Object obj = aClass.newInstance();
            Method method = aClass.getMethod("printInfo");
            method.invoke(obj);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
